package com.yanmushi.ms.client.annotation;

import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext;
import org.springframework.context.annotation.Configuration;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @Author yinlei
 * @Date 2018/4/18
 * @Desc todo
 */
@Configuration
@WebFilter(urlPatterns = "/*")
public class HystrixFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HystrixRequestContext context = HystrixRequestContext.initializeContext();
        try {
            chain.doFilter(request,response);
        } finally {
            context.shutdown();
        }
    }

    @Override
    public void destroy() {

    }
}
